package zhaomh.catgirl;

import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;

import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.DoubleStream;

public class zTools {
    Player pl = null;
    String n;
    public Server getServer () {
        return getPlugin().getServer();
    }
    public String colorReplace(String str) {
        return str.replace("&","§");
    }
    public zTools(String name , Player p){
        pl = p;
        n = name.replace("&","§");
    }
    public void sendM(String str){
        str = str.replace("&","§");
        pl.sendMessage(str);

    }
    public void sendM2(String str){
        str = str.replace("&","§");
        pl.sendMessage(n + " " + str);

    }
    public List<String> getPlayerNames(){
        List<String> l = new ArrayList<>();
        List<? extends Player> players;
        players = Bukkit.getServer().getOnlinePlayers().stream().toList();

        for (int i = 0; i < players.size(); i++) {
            l.add(players.get(i).getName());
        }

        return l;
    }
    public List<String> getKeysAtPath(YamlConfiguration config, String path) {
        List<String> keys = new ArrayList<>();

            // 获取指定路径下的配置内容
            ConfigurationSection section = config.getConfigurationSection(path);

            // 如果路径下的内容是一个Section，则获取其keys
            if (section != null) {
                // 获取section的直接子keys
                keys.addAll(section.getKeys(false));
            }

        return keys;
    }
    public CatGirl getPlugin () {
        return CatGirl.getPlugin(CatGirl.class);
    }
    public void setPlayer(Player p) {
        pl = p;
    }
    public String getName() {
        return pl.getName();
    }
    public Player getPlayer() {
        return pl;
    }
    public Player getNamePlayer (String name) {

        Player playerExact = getServer().getPlayerExact(name);
        return playerExact;
    }
    public void sendAllServerMessage (String str) {
        getServer().broadcastMessage(colorReplace(str));
    }
    public int getRandom(int min, int max) {
        return ThreadLocalRandom.current().nextInt(min,max);
    }
}
